// Project: Salient
// http://salient.codeplex.com
// 
// Copyright 2010, Sky Sanders <sky at skysanders.net>
// Dual licensed under the MIT or GPL Version 2 licenses.
// http://salient.codeplex.com/license
// 
// Date: April 25 2010 

#region

using System;
using System.Collections.Generic;
using System.ComponentModel;

#endregion

namespace Salient.Reflection
{
    /// <summary>
    /// Meta for WMI mapping
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class DescriptorAttribute : Attribute
    {
        // a common property cache - reflection is done but once for any one type.
        private static readonly Dictionary<Type, PropertyDescriptorCollection> Props;

        static DescriptorAttribute()
        {
            Props = new Dictionary<Type, PropertyDescriptorCollection>();
        }

        ///<summary>
        ///</summary>
        ///<param name="name"></param>
        ///<param name="type"></param>
        public DescriptorAttribute(string name, Type type)
        {
            Name = name;
            Type = type;
        }

        ///<summary>
        ///</summary>
        public PropertyDescriptorCollection Properties
        {
            get
            {
                if (!Props.ContainsKey(Type))
                {
                    Props.Add(Type, TypeDescriptor.GetProperties(Type));
                }
                return Props[Type];
            }
        }

        /// <summary>
        /// The type from which to reflect property info. 
        /// In all cases will be the type that is decorated.
        /// </summary>
        public Type Type { get; private set; }

        /// <summary>
        /// The WMI class to query
        /// </summary>
        public string Name { get; private set; }
    }
}